import java.util.HashSet;
import java.util.Iterator;

public class testwork2 {
    public int numJewelsInStones(String jewels, String stones) {
        int sum=0;
        for (int i=0;i<jewels.length();i++){
            char a=jewels.charAt(i);
            for (int j = 0; j <stones.length() ; j++) {
                char s=stones.charAt(j);
                if(a==s){
                    sum++;
                }
            }
        }
        return sum;
    }
    public int numJewelsInStones2(String jewels, String stones) {
        HashSet<Character> set=new HashSet<>();
        for(int i=0;i<jewels.length();i++){
            set.add(jewels.charAt(i));
        }
        int sum=0;
        for(int i=0;i<stones.length();i++){
            if(set.contains(stones.charAt(i))){
                sum++;
            }
        }
        return sum;
    }
}
